<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">体检信息</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>体检信息</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：<select id="phy-search-key">
            <option value="">-请选择-</option>
            <option value="ksh">考生号</option>
            <option value="xm">姓名</option>
            <option value="tjjl">体检结论</option>
        </select>
            <input id="phy-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="phy-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="phy-table" lay-filter="phy-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="phy-tab-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="export">
        <span class="layui-icon layui-icon-export" title="导出"></span>
    </a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="details">
        <span class="layui-icon layui-icon-about" title="详情"></span>
    </a>
</script>

<script type="text/html" id="phy-tab-toolbar">
    <a class="layui-btn layui-btn-primary layui-btn-md" lay-event="exportWord" title="批量导出Word">
        导出Word
    </a>
    <a class="layui-btn layui-btn-primary layui-btn-md" lay-event="exportExcel" title="批量导出Excel">
        导出Excel
    </a>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin', 'excel'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
        let excel = layui.excel;

        // 渲染表格
        var renderTable = function () {
            table.render({
                elem: '#phy-table',
                // url: config.base_server + 'user_query.json',
                url: config.base_server + 'api-firebird/fireBird/getPhyExmInfoList',
                method: 'GET',
                where: {
                    access_token: config.getToken().access_token,
                },
                page: true,
                toolbar: '#phy-tab-toolbar', //让工具栏左侧显示默认的内置模板
                cols: [[
                    {type: 'checkbox'},
                    {type: 'numbers'},
                    {field: 'candiNum', title: '考生号'},
                    {field: 'candiName', title: '姓名'},
                    {field: 'gender', title: '性别'},
                    {field: 'height', title: '身高', sort: true},
                    {field: 'weight', title: '体重', sort: true},
                    {field: 'phyExmCon', title: '体检结论', sort: true},
                    {align: 'center', toolbar: '#phy-tab-bar', title: '操作', width: 150}
                ]]
            });
        };
        renderTable();
        // 工具条点击事件
        table.on('tool(phy-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'details') { // 查看表字段
                showEditModel(data);
            } else if (layEvent === 'export') {
                layer.load();
                admin.req('api-firebird/fireBird/exportPhyExmInfo', JSON.stringify(data), function (res) {
                    layer.closeAll('loading');
                    layer.alert(res.msg);
                }, 'POST');
            }
        });

        //显示表单弹窗
        var showEditModel = function (data) {
            admin.putTempData('t_phy_info', data);
            var title = data.candiNum + " - " + data.candiName + " - 体检信息";
            admin.popupCenter({
                title: title,
                path: 'pages/business/phyexm_details.html',
                area: ['800px', '740px'],
                offset: [0, 0],
                scrollbar: true
            });
        };

        table.on('toolbar(phy-table)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            let layEvent = obj.event;
            let data = checkStatus.data;
            switch (layEvent) {
                case 'exportWord':
                    layer.load();
                    if (data.length <= 0) {
                        admin.req('api-firebird/fireBird/getPhyExmInfoList', {}, function (res) {
                            data = res.data;
                        }, 'GET');
                    }
                    admin.req('api-firebird/fireBird/exportPhyExmInfo', JSON.stringify(data), function (res) {
                        layer.closeAll('loading');
                        layer.alert(res.msg);
                    }, 'POST');
                    break;
                case 'exportExcel':
                    // let thead = ['体检id','考生号', '姓名', '性别', '体检号', '既往病史', '既往病史标志',
                    //     '左眼裸眼视力', '右眼裸眼视力', '左眼矫正视力', '右眼矫正视力', '左眼矫正度数', '右眼矫正度数',
                    //     '色觉检查', '色觉检查图', '视觉单色红', '视觉单色黄', '视觉单色绿', '视觉单色蓝', '视觉单色紫',
                    //     '眼病', '眼科医师意见', '收缩压', '舒张压', '发育情况', '心脏及血管', '呼吸系统', '神经系统',
                    //     '肝', '肝性质', '脾', '脾性质', '内科其他', '内科医师意见', '身高','体重','皮肤',
                    //     '面部','颈部','脊柱','四肢','关节','外科其他','外科医师意见',
                    //     '左耳听力','右耳听力','嗅觉','耳鼻咽喉','耳鼻喉科医师意见',
                    //     '唇腭','牙齿','是否口吃','口腔科其他','口腔科医师意见',
                    //     '胸透','胸透其他','胸透医师意见','转氨酶','乙肝抗原','肝其他','肝医师意见',
                    //     '专业受限1','专业受限2','专业受限3','专业受限4','专业受限5','专业受限6',
                    //     '体检结论','体检备注'];
                    let thead = [{
                        phyExmNum: '体检号',
                        candiNum: '考生号',
                        candiName: '姓名',
                        gender: '性别',
                        pstMdcHis: '既往病史',
                        pstMdcHisNote: '既往病史标志',
                        lefEyeUncVslAct: '左眼裸眼视力',
                        rigEyeUncVslAct: '右眼裸眼视力',
                        lefEyeCorVslAct: '左眼矫正视力',
                        rigEyeCorVslAct: '右眼矫正视力',
                        lefEyeCorDeg: '左眼矫正度数',
                        rigEyeCorDeg: '右眼矫正度数',
                        colVsTest: '色觉检查',
                        colVsChart: '色觉检查图',
                        colVsMnChrRed: '视觉单色红',
                        colVsMnChrYel: '视觉单色黄',
                        colVsMnChrGre: '视觉单色绿',
                        colVsMnChrBlu: '视觉单色蓝',
                        colVsMnChrPur: '视觉单色紫',
                        eyeDis: '眼病',
                        eyeOpn: '眼科医师意见',
                        systolicPres: '收缩压',
                        diastolicPres: '舒张压',
                        develop: '发育情况',
                        heartAndBldVsl: '心脏及血管',
                        respSys: '呼吸系统',
                        nervousSys: '神经系统',
                        liver: '肝',
                        liverNature: '肝性质',
                        spleen: '脾',
                        spleenNature: '脾性质',
                        internMdcOther: '内科其他',
                        internMdcOpn: '内科医师意见',
                        height: '身高',
                        weight: '体重',
                        skin: '皮肤',
                        face: '面部',
                        neck: '颈部',
                        spine: '脊柱',
                        limb: '四肢',
                        joint: '关节',
                        surgeOther: '外科其他',
                        surgeOpn: '外科医师意见',
                        lefEarHear: '左耳听力',
                        rigEarHear: '右耳听力',
                        smell: '嗅觉',
                        etn: '耳鼻咽喉',
                        etnOpn: '耳鼻喉科医师意见',
                        lipAndPalate: '唇腭',
                        teeth: '牙齿',
                        isStutter: '是否口吃',
                        oralCavOther: '口腔科其他',
                        oralCavOpn: '口腔科医师意见',
                        chestXRay: '胸透',
                        chestXRayOther: '胸透其他',
                        chestXRayOpn: '胸透医师意见',
                        trans: '转氨酶',
                        hepBAntigen: '乙肝抗原',
                        liverOther: '肝其他',
                        liverOpn: '肝医师意见',
                        profLim1: '专业受限1',
                        profLim2: '专业受限2',
                        profLim3: '专业受限3',
                        profLim4: '专业受限4',
                        profLim5: '专业受限5',
                        profLim6: '专业受限6',
                        phyExmCon: '体检结论',
                        phyExamNote: '体检备注'
                    }];
                    //如果未选中数据，则视为导出全部数据
                    if (data.length <= 0) {
                        admin.req('api-firebird/fireBird/getPhyExmInfoList', {}, function (res) {
                            data = res.data;
                        }, 'GET');
                    }
                    let filterdata = ['phyExmNum', 'candiNum', 'candiName', 'gender',
                        'pstMdcHis', 'pstMdcHisNote', 'lefEyeUncVslAct',
                        'rigEyeUncVslAct', 'lefEyeCorVslAct', 'rigEyeCorVslAct',
                        'lefEyeCorDeg', 'rigEyeCorDeg', 'colVsTest',
                        'colVsChart', 'colVsMnChrRed', 'colVsMnChrYel',
                        'colVsMnChrGre', 'colVsMnChrBlu', 'colVsMnChrPur',
                        'eyeDis', 'eyeOpn', 'systolicPres', 'diastolicPres',
                        'develop', 'heartAndBldVsl', 'respSys', 'nervousSys',
                        'liver', 'liverNature', 'spleen', 'spleenNature', 'internMdcOther',
                        'internMdcOpn', 'height', 'weight', 'skin', 'face', 'neck',
                        'spine', 'limb', 'joint', 'surgeOther', 'surgeOpn',
                        'lefEarHear', 'rigEarHear', 'smell', 'etn', 'etnOpn',
                        'lipAndPalate', 'teeth', 'isStutter', 'oralCavOther', 'oralCavOpn',
                        'chestXRay', 'chestXRayOther', 'chestXRayOpn', 'trans', 'hepBAntigen',
                        'liverOther', 'liverOpn', 'profLim1', 'profLim2', 'profLim3',
                        'profLim4', 'profLim5', 'profLim6', 'phyExmCon', 'phyExamNote'];
                    data = excel.filterExportData(data, filterdata);
                    thead.push.apply(thead, data);
                    excel.exportExcel(thead, '学生体检信息表.xlsx', 'xlsx');
                    // table.exportFile(thead,data, 'xls');
                    break;
            }
        })

        $("#phy-btn-search").click(function () {
            let key = $("#phy-search-key").val();
            let value = $("#phy-search-value").val();
            if (key!='ksh')
                value = value + '%';
            table.reload('phy-table', {where: {searchKey: key,searchValue: value}});
        });
    });
</script>